(function ($) {
    "use strict";

    /*==================================================================
    [ Focus Contact2 ]*/
    $('.input100').each(function () {
        $(this).on('blur', function () {
            if ($(this).val().trim() !== "") {
                $(this).addClass('has-val');
            } else {
                $(this).removeClass('has-val');
            }
        })
    })

    /*==================================================================
    [ Validate ]*/
    let input = $('.validate-input .input100');
    let check = true;

    function checkHandler(){
        for (let i = 0; i < input.length; i++) {
            if (validate(input[i]) === false) {
                showValidate(input[i]);
                check = false;
            }
        }
    }
    $('.validate-form').on('submit', function () {
        checkHandler();
        return check;
    });


    $('.validate-form .input100').each(function () {
        $(this).focus(function () {
            hideValidate(this);
        });
    });

    function validate(input) {
        if ($(input).val().trim() === '') {
            return false;
        }
    }

    function showValidate(input) {
        let thisAlert = $(input).parent();

        $(thisAlert).addClass('alert-validate');
    }

    function hideValidate(input) {
        let thisAlert = $(input).parent();

        $(thisAlert).removeClass('alert-validate');
    }


    /*
    *
    * ********************************验证码************************************
    *
    * */

    /*
    * 为了使每次生成图片不一致，即不让浏览器读缓存，所以需要加上时间戳
    * */
    function changeUrl(url) {
        let timestamp = (new Date()).valueOf();
        url = url + "".substring(0, 17);
        if ((url.indexOf("&") >= 0)) {
            url = url + "×tamp=" + timestamp;
        } else {
            url = url + "?timestamp=" + timestamp;
        }
        return url;
    }

    function changeImg() {
        let imgSrc = $("#img");
        let src = imgSrc.attr("src");
        imgSrc.attr("src", changeUrl(src));
    }

    $(".div-img").on('click',function () {
        changeImg();
    })


})(jQuery);